﻿/* 点击单位触发的事件 */
function groupnode_click(sender) {
	var groupnode = $(sender);
	var groupname = groupnode.find('span').html();
	var groupid = groupnode.find('input[type="hidden"]').val();

	var isExist = false;
	var writemail_recievercontainer_recievers = $('#writemail_recievercontainer_recievers');

	writemail_recievercontainer_recievers.find('span.selectedgroup').each(function () {
		if ($(this).html() == groupname) {
			isExist = true;
		}
	});

	if (!isExist) {
		var uitem = '<div class="selectedgroupcontainer" onclick="selectedgroupcontainer_click(this);" title="点击移除">' +
											 '<span class="selectedgroup">' + groupname + '</span>' +
											 '<input type="hidden" id="user' + groupid + '" value="' + groupid + '"></input>' +
										'</div>';

		writemail_recievercontainer_recievers.find('span.tip').remove();
		writemail_recievercontainer_recievers.append(uitem);
	}
}

function selectedgroupcontainer_click(sender) {
	$(sender).remove();
}

function node_onmouseout(sender) {
	$(sender).removeClass('groupnode_hover');
}

function node_onmouseover(sender) {
	$(sender).addClass('groupnode_hover');
}

function btnSend_ClientClick(sender) {
	var hasrecievers = false;
	var writemail_recievercontainer_recievers = $('#writemail_recievercontainer_recievers');

	hasrecievers = (writemail_recievercontainer_recievers.find('span.selectedgroup').length > 0);

	if (!hasrecievers) {
		$('#failurenotification_recievers').show();
	}
	else {
		var recievers = '';
		writemail_recievercontainer_recievers.find('input[type="hidden"]').each(function () {
			var userName = $(this).val();

			recievers = recievers + ' ' + userName;
		});

		$('#hfMailRecievers').val(recievers);
	}

	Page_ClientValidate("writemail");
	
	return hasrecievers && Page_IsValid;
}

$(window).load(function () {
	var h = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - $('.header').height() - $('.footer').height() - 10 - $('.pagetitle').height() - 45;

	$('#mail_writemailpage').height(h);
	$('#mail_recievercontainer').height(h);
	$('#mail_writemailcontent').height(h);
	$('#groupuserscontainer').height(h - 50);

	var editor = CKEDITOR.config.height = h - 350;
});